unit uPrincpal;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DBXDataSnap, DBXCommon, DB, SqlExpr, Unit1,
   MMSystem, ImgList, ComCtrls, ToolWin, ActnList, Menus,ClipBrd;

type
  TForm1 = class(TForm)
    SQLConnection1: TSQLConnection;
    ActionList1: TActionList;
    playpause: TAction;
    maisvolume: TAction;
    menosvolume: TAction;
    close: TAction;
    anterior: TAction;
    proximo: TAction;
    ImageList1: TImageList;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    PopupMenu1: TPopupMenu;
    Refresh: TAction;
    Refresh1: TMenuItem;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    ToolButton7: TToolButton;
    actclipboard: TAction;
    ToolButton8: TToolButton;
    ToolButton9: TToolButton;
    actKeyBoard: TAction;
    function GetServerMethods : TServerMethods1Client;
    procedure FormCreate(Sender: TObject);
    procedure playpauseExecute(Sender: TObject);
    procedure menosvolumeExecute(Sender: TObject);
    procedure closeExecute(Sender: TObject);
    procedure anteriorExecute(Sender: TObject);
    procedure proximoExecute(Sender: TObject);
    procedure JvXPToolButton1Click(Sender: TObject);
    procedure SimulaTecla(NunTecla : Integer);
    procedure maisvolumeExecute(Sender: TObject);{ procedura para simular teclado do quick play }
    procedure Connecta;
    procedure RefreshExecute(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure actclipboardExecute(Sender: TObject);
    procedure TransClip();
    procedure actKeyBoardExecute(Sender: TObject);{transfere o oque esta no clipboard para p cliente}
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Finstance : TServerMethods1Client;
  Form1: TForm1;

implementation

uses
  uIpConf, Unit4;

{$R *.dfm}

procedure TForm1.actKeyBoardExecute(Sender: TObject);
var
KeyBord : TForm4;
begin
if Assigned(KeyBord) then
  KeyBord := TForm4.Create(NIL);

  KeyBord.ShowModal;
end;

procedure TForm1.anteriorExecute(Sender: TObject);
begin
  SimulaTecla(177);
end;

procedure TForm1.actclipboardExecute(Sender: TObject);
begin
  TransClip;
end;

procedure TForm1.closeExecute(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TForm1.Connecta;
Var
ip : TForm3;
begin
  SQLConnection1.Close;
  Ip := TForm3.create(Nil);
  Ip.ShowModal;
  SQLConnection1.Params.Values['HostName'] := Ip.Ip;
  FreeAndNil(Ip);
  SQLConnection1.Open;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Connecta();
end;

procedure TForm1.FormShow(Sender: TObject);
begin
{ seta a altura e lagura para se ajustar o toolbar }
  Self.Width  := 208;
  Self.Height := 23;
end;

function TForm1.GetServerMethods: TServerMethods1Client;
begin
if FInstance = nil then
begin
  Finstance := TServerMethods1Client.Create(SQLConnection1.DBXConnection);
end;
Result := Finstance;
end;


procedure TForm1.JvXPToolButton1Click(Sender: TObject);
begin
  Application.Terminate
end;

procedure TForm1.maisvolumeExecute(Sender: TObject);
begin
  SimulaTecla(175);
end;

procedure TForm1.menosvolumeExecute(Sender: TObject);
begin
  SimulaTecla(174);
end;

procedure TForm1.playpauseExecute(Sender: TObject);
begin
  SimulaTecla(179);
end;

procedure TForm1.proximoExecute(Sender: TObject);
begin
  SimulaTecla(176);
end;

procedure TForm1.RefreshExecute(Sender: TObject);
begin
  Self.Hide;
  Connecta;
  Self.Show;
end;

procedure TForm1.SimulaTecla(NunTecla : Integer);
begin
{ Esta procedure tem como tratar o retorno boolean da function ClickBtn
  Os retornos True e False sao referentes ao tratamento de excption do servidor  }
  if not GetServerMethods.ClickBtn(NunTecla) then
  Begin
    ShowMessage('Erro ao emultar tecla');
  End;

end;

procedure TForm1.TransClip;
begin
GetServerMethods.Cclipboard(Clipboard.AsText);
end;

end.
